#include "stdafx.h"
#include "Analyze.h"
#include <wtypes.h>
#include "..\Parser.h"

BOOL logic_desc_first()
{
	SymbolStack.Pop(); // not
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etNot);
	Node->Child().Add(ParserAnalyze.Pop());
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL logic_desc_second()
{
	NAutoPtr<CSyntaxTreeNode> Op2 = ParserAnalyze.Pop();
	NAutoPtr<CSyntaxTreeNode> Op1 = ParserAnalyze.Pop();
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node;
	switch(Ptr->Length())
	{
	case 3: // and's length is 3
		Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etAnd);
		break;
	case 2: // or's length is 2
		Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etOr);
		break;
	}
	Node->Child().Add(Op1);
	Node->Child().Add(Op2);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL value_desc_symbol_first()
{
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etSymbol);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL value_desc_string()
{
	CLexer_Token_Ptr Ptr = StringStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etString);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL value_desc_number()
{
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etNumber);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL value_desc_true()
{
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etTrue);
	ParserAnalyze.Push(Node);
	return TRUE;
}

BOOL value_desc_false()
{
	CLexer_Token_Ptr Ptr = SymbolStack.Pop();
	NAutoPtr<CSyntaxTreeNode> Node = new CSyntaxTreeNode(CSyntaxTreeNode::stExp,CSyntaxTreeNode::etFalse);
	ParserAnalyze.Push(Node);
	return TRUE;
}